package com.ihrm.employee.dao;

import com.ihrm.domain.employee.UserCompanyPersonal;
import com.ihrm.domain.employee.response.EmployeeReportResult;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserCompanyPersonalDao extends JpaRepository<UserCompanyPersonal,String>, JpaSpecificationExecutor<UserCompanyPersonal> {

    UserCompanyPersonal findByUserId(String uid);
    
    /**
     * ON a.user_id=b.user_id
     * WHERE a.time_of_entry LIKE `2018-02%` OR (b.resignation_time LIKE "2018-02%")
     */
    @Query(value = "select new com.ihrm.domain.employee.response.EmployeeReportResult(a,b) from UserCompanyPersonal a "+
    "left join EmployeeResignation b on a.userId=b.userId where a.companyId=?1 and a.timeOfEntry like ?2 or ("+
    "b.resignationTime like ?2)")
    List<EmployeeReportResult> findByReport(String companyId,String month);
}
